<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script>
        var personStr = '{"name":"张三","age":"18","girlFriend":{"name":"翠花","age":"20"},"foods":["苹果","香蕉","桃子"],"pets":[{"petName":"大黄","petType":"dog"},{"petName":"二黄","petType":"cat"}]}';
        console.log(personStr);
        console.log(typeof personStr);

        // 可以通过 JSON.parse() 将一个 JSON 串转换为一个对象~
        var person = JSON.parse(personStr);
        console.log(person);
        console.log(typeof person);
        console.log(person.girlFriend.name);
        // 可以通过 JSON.stringify() 再将一个对象转换成 JSON 串
        var personStr2 = JSON.stringify(person);
        console.log(personStr2);
    </script> 
</head>
<body>
    
</body>
</html>